#站点统计页面
from selenium.webdriver.common.by import By
from base.base import Base
import json
from util.number_util import get_number
with open(r'data\json_data\Statistics.json','r',encoding='utf-8') as f:
    data = json.load(f)['page']
class PageStatistics(Base):
    pagetitle_locator = (By.XPATH,'(//li[@role="menuitem"])[2]')
    site_xq_locator = (By.XPATH, f"//span[contains(text(), '{data['sitename']}')]")
    #站点查询框
    site_input_locator = (By.XPATH,'//input[@placeholder="站点搜索"]')
    #查询数据信息
    search_message_locator = (By.CLASS_NAME,'ant-empty-description')
    #顶部数据
    topvalues_locator = (By.XPATH,'//div[@class = "scene-statistics"]//h1')
    #告警列表
    alar_locator = (By.XPATH,'//tbody//*[contains(@class,"ant-table-cell")]')
    #设备概览列表
    devices_locator = (By.XPATH,'//div[@class="device-item"]')
    #站点页面跳转
    def page_jump(self):
        self.click(self.pagetitle_locator)
    #站点搜索框输入
    def site_input(self,values):
        self.clear(self.site_input_locator)
        self.input(self.site_input_locator,values)
    #获取搜索框文本
    def get_search_message(self):
        return self.find(self.search_message_locator).text
    #点击指定站点
    def site_click(self):
        self.click(self.site_xq_locator)
    #获取顶部数据
    def get_topvalues(self):
        values = []
        for elm in self.finds(self.topvalues_locator):
            values.append(elm.text)
        values = get_number(values)
        return values
    #获取告警列表数据,可以复用系统首页告警列表
    def get_alarmlist(self):
        values = []
        for elm in self.finds(self.alar_locator):
            values.append(elm.text)
        return values
    #获取设备概览信息
    def get_deviceslist(self):
        values = []
        newvalues = []
        for elm in self.finds(self.devices_locator):
            values.append(elm.text)
        for value in values:
            newvalue = value.split('\n')
            for i,key in enumerate(newvalue):
                if i == 0:
                    newvalues.append(key)
                else:
                    newvalues.append(key.split('：')[1].split('℃')[0])
        return newvalues